//
//  UILabel+SGPagingLabel.m
//  lTTheOne
//
//  Created by 1 on 2024/6/10.
//

#import "UILabel+SGPagingLabel.h"

@implementation UILabel (SGPagingLabel)


- (void)setPadding:(UIEdgeInsets)padding {
    
    self.padding = padding;
    
    // 重新设置label的frame，包含内边距
    CGRect rect = self.bounds;
    rect.origin.x += padding.left;
    rect.origin.y += padding.top;
    rect.size.width -= padding.left + padding.right;
    rect.size.height -= padding.top + padding.bottom;
    
    self.bounds = rect;
    
    // 更新preferredMaxLayoutWidth
    if (self.numberOfLines == 0) {
        self.preferredMaxLayoutWidth = rect.size.width - padding.left - padding.right;
    }
}

- (UIEdgeInsets)padding {
    return self.padding;
}

@end
